package leecode.二分法;

public class 寻找旋转排序数组的值 {
    public static void main(String[] args) {
        Soulution soulution = new Soulution();
        int nums = soulution.nums(new int[]{4, 5, 6, 7, 0, 1, 2, 3}, 2);
        System.out.println(nums);

    }

    static class Soulution{
        public int nums(int[] nums, int target) {
            int l=0,r=nums.length-1;
            while(l<=r){
                int mid=l+(r-l)/2;
                if(nums[mid]==target){
                    return mid;
                }
                if(nums[mid]>nums[r]){
                    if(nums[mid]>target&&target>=nums[l]){
                        r=mid-1;
                    }
                    else{
                        l=mid+1;
                    }
                }
                else{
                    if(nums[mid]<target&&target<=nums[r]){
                        l=mid+1;
                    }
                    else{
                        r=mid-1;
                    }
                }
            }
            return -1;

        }
    }
}
